package com.cehome.cloudbox.listener;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.cehome.cloudbox.constans.ExtensionTaskProperties;
import com.cehome.cloudbox.doman.dto.ProcCallBackParamDto;
import com.cehome.cloudbox.enums.ProcIncStateEnum;
import com.cehome.cloudbox.service.IProcCommonService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * 全局的流程完成监听
 * @author zfl
 */
@Component
@Slf4j
public class GlobalProcessCompletedListener extends AbstractFlowableEngineEventListener {

    @Resource
    protected RepositoryService repositoryService;
    @Resource
    private IProcCommonService iProcCommonService;


    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        log.info("全局的流程完成监听开始，流程实例ID：{}", event.getProcessInstanceId());
        ExecutionEntity executionEntity = (ExecutionEntity) event.getEntity();
        // 流程实例状态
        String procInsState = Convert.toStr(executionEntity.getVariable(ExtensionTaskProperties.FLOWABLE_PROCESS_INSTANCE_STATE));

        // 获取节点信息
        BpmnModel bpmnModel = repositoryService.getBpmnModel(event.getProcessDefinitionId());
        Process process = bpmnModel.getProcesses().get(0);
    }

}
